import { jsx as _jsx } from "react/jsx-runtime";
import { TextBox } from "devextreme-react";
import notify from "devextreme/ui/notify";
import React, { PureComponent } from "react";
/**
 * ~~~js
 * import DevPopup,{ DevInputPopups }  from 'sright-ui'
 * ~~~
 */
export function InputPopup(WrappedComponent) {
    class PTextBox extends PureComponent {
        state = {
            value: "",
        };
        textBoxRef;
        initValue = (value) => this.setState({ value });
        handleChange = (e) => {
            const { event } = e;
            console.log(event.target.value);
            this.setState({
                value: event.target.value,
            });
        };
        handleKeyDown = (e) => {
            const { event } = e;
            if (event.keyCode === 13) {
                event.preventDefault();
                if (this.props.onKeyDownTextBox) {
                    this.props.onKeyDownTextBox();
                }
            }
        };
        render() {
            this.textBoxRef = React.createRef();
            return (_jsx(TextBox, { ref: this.textBoxRef, value: this.state.value, onInput: this.handleChange.bind(this), onEnterKey: this.handleKeyDown.bind(this) }));
        }
    }
    return class extends PureComponent {
        state = {
            user: null,
            Visible: false,
            title: "",
        };
        gridRef;
        pTextBoxRef;
        defaultConfig = {
            width: "400",
            height: "200",
        };
        show = (params) => {
            this.gridRef.current.refs = params;
            this.setState({
                Visible: true,
                title: params.title,
            });
            this.pTextBoxRef.current.initValue(params.value);
        };
        okFunctionCallback = () => {
            const content = this.pTextBoxRef.current.state.value;
            if (!content)
                return notify(`请输入内容`, "warning", 2000);
            if (this.gridRef.current.refs?.regExpFunc) {
                const res = this.gridRef.current.refs?.regExpFunc(content);
                if (res) {
                    this.gridRef.current.refs?.okCallback(content);
                    this.setState({
                        Visible: false,
                    });
                    return;
                }
                return;
            }
            this.gridRef.current.refs?.okCallback(content);
            this.setState({
                Visible: false,
            });
        };
        render() {
            this.gridRef = React.createRef();
            this.pTextBoxRef = React.createRef();
            let props = {
                ...this.defaultConfig,
                ...this.props,
                // onchange: this.onchange,
            };
            const { title, Visible } = this.state;
            return (_jsx(WrappedComponent, { ...props, ref: this.gridRef, title: title, visible: Visible, onHiding: () => {
                    this.setState({
                        Visible: false,
                    });
                }, toolbarItems: [
                    {
                        widget: "dxButton",
                        toolbar: "bottom",
                        location: "after",
                        options: {
                            text: "取消",
                            onClick: () => {
                                this.setState({
                                    Visible: false,
                                });
                            },
                        },
                    },
                    {
                        widget: "dxButton",
                        toolbar: "bottom",
                        location: "after",
                        options: {
                            text: props?.okText ? props.okText : "确定",
                            type: "default",
                            onClick: () => this.okFunctionCallback(),
                        },
                    },
                ], children: _jsx(PTextBox, { ref: this.pTextBoxRef, onKeyDownTextBox: this.okFunctionCallback.bind(this) }) }));
        }
    };
}
